"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Clock {
    constructor(useInterval = false) {
        this.running = false;
        this.now = Date.now;
        this.start(useInterval);
    }
    start(useInterval = false) {
        this.deltaTime = 0;
        this.currentTime = this.now();
        this.elapsedTime = 0;
        this.running = true;
        if (useInterval) {
            // auto set interval to 60 ticks per second
            this._interval = setInterval(this.tick.bind(this), 1000 / 60);
        }
    }
    stop() {
        this.running = false;
        if (this._interval) {
            clearInterval(this._interval);
        }
    }
    tick(newTime = this.now()) {
        this.deltaTime = newTime - this.currentTime;
        this.currentTime = newTime;
        this.elapsedTime += this.deltaTime;
    }
}
exports.default = Clock;
